# Contributor: knuxify <knuxify@gmail.com>
# Maintainer:
pkgname=projectm
pkgver=3.1.12
pkgrel=2
pkgdesc="Music visualizer which uses 3D accelerated iterative image based rendering"
url="https://github.com/projectM-visualizer/projectm"
arch="all"
license="LGPL-2.1-or-later"
makedepends="mesa-gl glm-dev mesa-dev musl-fts-dev qt5-qtbase-dev sdl2-dev pulseaudio-dev"
subpackages="$pkgname-dev $pkgname-presets $pkgname-sdl $pkgname-pulseaudio
	$pkgname-pulseaudio-doc:pulseaudio_doc"
source="https://github.com/projectM-visualizer/projectm/releases/download/v$pkgver/projectM-$pkgver.tar.gz
	fix-missing-gl-symbols-on-arm.patch"
builddir="$srcdir/projectM-$pkgver"

prepare() {
	default_prepare
	update_config_sub
}

build() {
	export LDFLAGS="$LDFLAGS -lfts"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-gles \
		--enable-sdl \
		--enable-threading \
		--enable-pulseaudio \
		--enable-qt
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install-data-am
	cd "$builddir/src"
	make DESTDIR="$pkgdir" install-am
	cd "$builddir/src/libprojectM"
	make DESTDIR="$pkgdir" install
	# Presets
	cd "$builddir/src/NativePresets"
	make DESTDIR="$pkgdir" install
	# SDL
	cd "$builddir/src/projectM-sdl"
	make DESTDIR="$pkgdir" install
	# Pulseaudio
	cd "$builddir/src/projectM-pulseaudio"
	make DESTDIR="$pkgdir" install
	# Running the make commands in separate functions for these three fails,
	# so we run them here and move the files out in the subpackage-specific
	# functions instead.
}

presets() {
	pkgdesc="Music visualizer which uses 3D accelerated iterative image based rendering (presets)"
	mkdir -p "$subpkgdir"/usr/share/projectM
	mv "$pkgdir"/usr/share/projectM/presets \
		"$subpkgdir"/usr/share/projectM
}

sdl() {
	pkgdesc="Music visualizer which uses 3D accelerated iterative image based rendering (sdl)"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/projectMSDL "$subpkgdir"/usr/bin/projectMSDL
}

pulseaudio() {
	pkgdesc="Music visualizer which uses 3D accelerated iterative image based rendering (pulseaudio)"
	mkdir -p "$subpkgdir"/usr/share/icons/hicolor/scalable/apps
	mv "$pkgdir"/usr/share/icons/hicolor/scalable/apps/projectM.svg \
		"$subpkgdir"/usr/share/icons/hicolor/scalable/apps/projectM.svg
	mkdir -p "$subpkgdir"/usr/share/applications
	mv "$pkgdir"/usr/share/applications/projectM-pulseaudio.desktop \
		"$subpkgdir"/usr/share/applications/projectM-pulseaudio.desktop
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/projectM-pulseaudio "$subpkgdir"/usr/bin/projectM-pulseaudio
}

pulseaudio_doc() {
	pkgdesc="Music visualizer which uses 3D accelerated iterative image based rendering (pulseaudio documentation)"
	mkdir -p "$subpkgdir"/usr/share/man/man1
	mv "$pkgdir"/usr/share/man/man1/projectM-pulseaudio.1 \
		"$subpkgdir"/usr/share/man/man1/projectM-pulseaudio.1
	rm -r "$pkgdir"/usr/share/man
	default_doc
}

sha512sums="
13aafc2ebd5eb4aa59b54d7c1d2933ed9a5c014899560a241079b725ffaed2e37f9ac451bb74a7fce235184ac795c55cb54c1d0f0c9e8c571e5cbda9cd3c4058  projectM-3.1.12.tar.gz
8250250f5b409b4806869da1a5692d441c6928bf0ababdcce8072df74d8f93b314bbfe2c60a4d2c25a6a4d0d8722e3bf62106c63694933a05022970a3cbf02d1  fix-missing-gl-symbols-on-arm.patch
"
